package com.lck.blogmanager.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lck.blogmanager.common.Response;
import com.lck.blogmanager.entity.TagEntity;
import com.lck.blogmanager.req.*;
import com.lck.blogmanager.res.BlogUserDetailRes;
import com.lck.blogmanager.res.DetailBlogRes;
import com.lck.blogmanager.res.PageBlogRes;
import com.lck.blogmanager.res.UserBlogListRes;
import com.lck.blogmanager.service.BlogService;
import com.lck.blogmanager.service.TagService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 博客
 * @author wyq
 * @version v1.0.0
 * @explain
 * @date 2024/4/7 18:29
 */
@RequestMapping("/blog")
@RequiredArgsConstructor
@Slf4j
@RestController
@CrossOrigin
public class BlogController {

    private final BlogService blogService;
    private final TagService tagService;

    /**
     * 用户博客列表
     * @param req
     * @return
     */
    @PostMapping("/userList")
    public Response<Page<UserBlogListRes>> userList(@RequestBody UserBlogListReq req){
        Page<UserBlogListRes> page = blogService.userList(req);
        return Response.success(page);
    }


    /**
     * 用户端查询博客详情
     * @param blogId
     * @return
     */
    @GetMapping("/userDetail/{blogId}")
    public Response<BlogUserDetailRes> userDetail(@PathVariable Integer blogId){
        BlogUserDetailRes res = blogService.userDetail(blogId);
        return Response.success(res);
    }


    /**
     * 获取所有标签
     * @return
     */
    @GetMapping("/getTag")
    public Response<List<TagEntity>> getTag(){
        List<TagEntity> list = tagService.getBlogTag();
        return Response.success(list);
    }


    /**
     * ---------------------------管理端
     */


    /**
     * 管理端博客列表
     * @param req
     * @return
     */
    @PostMapping("/page")
    public Response<Page<PageBlogRes>> pageBlog(@RequestBody PageBlogReq req){
        Page<PageBlogRes> page = blogService.pageBlog(req);
        return Response.success(page);
    }

    /**
     * 博客详情
     * @param blogId
     * @return
     */
    @GetMapping("/detail/{blogId}")
    public Response<DetailBlogRes> detailBlog(@PathVariable Integer blogId){
        DetailBlogRes res = blogService.detailBlog(blogId);
        return Response.success(res);
    }

    /**
     * 审核
     * @param req
     * @return
     */
    @PostMapping("/audit")
    public Response auditBlog(@RequestBody AuditBlogReq req){
        blogService.auditBlog(req);
        return Response.success();
    }


    /**
     * 点赞
     * @return
     */
    @GetMapping("/like")
    public Response likeBlog(Integer blogId){
        blogService.likeBlog(blogId);
        return Response.success();
    }

    /**
     * 收藏
     * @return
     */
    @PostMapping("/collect")
    public Response collectBlog(Integer blogId){
        blogService.collectBlog(blogId);
        return Response.success();
    }



}
